/*
 * Shapes.cpp
 *
 *  Created on: 21-dec.-2013
 *      Author: Axel
 */

#include <Shapes.h>
#include "extraMath.h"
#include <GL/glew.h>

Shapes::Shapes() {


}

Shapes::~Shapes() {

}

void Shapes::makeCube(float width, indix& indice, vertix& vert) {
	vert.vertices = new Vector3f[8];
	vert.len = 8;

	Vector3f vec;
	vec.z = width/2.0f;
	vec.x = width/2.0f;
	vec.y = width/2.0f;
	vert.vertices[0]  = vec;

	vec.x = -width/2.0f;
	vec.y = width/2.0f;
	vert.vertices[1]  = vec;

	vec.x = width/2.0f;
	vec.y = -width/2.0f;
	vert.vertices[2]  = vec;

	vec.x = -width/2.0f;
	vec.y = -width/2.0f;
	vert.vertices[3]  = vec;

	vec.z = -width/2.0f;
	vec.x = width/2.0f;
	vec.y = width/2.0f;
	vert.vertices[4]  = vec;

	vec.x = -width/2.0f;
	vec.y = width/2.0f;
	vert.vertices[5]  = vec;

	vec.x = width/2.0f;
	vec.y = -width/2.0f;
	vert.vertices[6]  = vec;

	vec.x = -width/2.0f;
	vec.y = -width/2.0f;
	vert.vertices[7]  = vec;

	indice.indices = new GLuint[36];
	indice.indices[0] = 2;
	indice.indices[0] = 5;
	indice.indices[0] = 7;
	indice.indices[0] = 2;
	indice.indices[0] = 5;
	indice.indices[0] = 3;
	indice.indices[0] = 2;
	indice.indices[0] = 6;
	indice.indices[0] = 7;

	indice.indices[0] = 2;
	indice.indices[0] = 6;
	indice.indices[0] = 0;
	indice.indices[0] = 0;
	indice.indices[0] = 4;
	indice.indices[0] = 6;
	indice.indices[0] = 0;
	indice.indices[0] = 4;
	indice.indices[0] = 1;

	indice.indices[0] = 1;
	indice.indices[0] = 4;
	indice.indices[0] = 5;
	indice.indices[0] = 1;
	indice.indices[0] = 3;
	indice.indices[0] = 5;
	indice.indices[0] = 1;
	indice.indices[0] = 3;
	indice.indices[0] = 0;

	indice.indices[0] = 3;
	indice.indices[0] = 2;
	indice.indices[0] = 0;
	indice.indices[0] = 5;
	indice.indices[0] = 6;
	indice.indices[0] = 7;
	indice.indices[0] = 5;
	indice.indices[0] = 6;
	indice.indices[0] = 2;

	indice.len = 36;

}

void Shapes::makeCircle(float width, indix& indice, vertix& vertex) {
	double angle=0;
	int ind=1;
	static const int triangles = 100;

	vertex.vertices = new Vector3f[triangles];
	indice.indices = new GLuint[triangles*3];
	vertex.len = triangles;
	indice.len = triangles*3;

	vertex.vertices[0] = Vector3f(0, 0, 0.0f);

	for(int i =1;i<triangles;i++) {
		vertex.vertices[i]=Vector3f(width*math::cos_axel(angle), width*math::sin_axel(angle), 0.0f);
		angle += (360.0/(triangles)) * PI / 180.0;
	}

	for(int i=0;i<(triangles)*3;i+=3) {
		indice.indices[i]= 0;
		indice.indices[i+1] = ind;
		indice.indices[i+2] = ind+1;
		if (ind+1 == triangles)
			indice.indices[i+2] = 1;
		ind++;
	}
}

void Shapes::makeRect(float width, float height, indix& indice, vertix& vertex) {
	vertex.vertices = new Vector3f[4];
	indice.indices = new GLuint[6];

	Vector3f vec;
	vec.x = width/2.0f;
	vec.y = height/2.0f;
	vertex.vertices[0]  = vec;

	vec.x = -width/2.0f;
	vec.y = height/2.0f;
	vertex.vertices[1]  = vec;

	vec.x = width/2.0f;
	vec.y = -height/2.0f;
	vertex.vertices[2]  = vec;

	vec.x = -width/2.0f;
	vec.y = -height/2.0f;
	vertex.vertices[3]  = vec;

	indice.indices[0] = 0;
	indice.indices[1] = 2;
	indice.indices[2] = 1;
	indice.indices[3] = 1;
	indice.indices[4] = 3;
	indice.indices[5] = 2;

	indice.len = 6;
	vertex.len = 4;
}

void Shapes::loadTexture() {
	GLuint textureID;
	glGenTextures(1, &textureID);

	glBindTexture(GL_TEXTURE_2D, textureID);

	glTexStorage2D(GL_TEXTURE_2D, 1,GL_RGBA32F, 256, 256);


}


